package com.ruoyi.whzj.controller;

import java.util.List;

import com.ruoyi.whzj.domain.WhzjBaseconfig;
import com.ruoyi.whzj.service.IWhzjBaseconfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 基本设置Controller
 * 
 * @author ruoyi
 * @date 2020-10-27
 */
@Controller
@RequestMapping("/whzj/baseconfig")
public class WhzjBaseconfigController extends BaseController
{
    private String prefix = "whzj/baseconfig";

    @Autowired
    private IWhzjBaseconfigService whzjBaseconfigService;

    @RequiresPermissions("whzj:baseconfig:view")
    @GetMapping()
    public String baseconfig()
    {
        return prefix + "/baseconfig";
    }

    /**
     * 查询基本设置列表
     */
    @RequiresPermissions("whzj:baseconfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WhzjBaseconfig whzjBaseconfig)
    {
        startPage();
        List<WhzjBaseconfig> list = whzjBaseconfigService.selectWhzjBaseconfigList(whzjBaseconfig);
        return getDataTable(list);
    }

    /**
     * 导出基本设置列表
     */
    @RequiresPermissions("whzj:baseconfig:export")
    @Log(title = "基本设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WhzjBaseconfig whzjBaseconfig)
    {
        List<WhzjBaseconfig> list = whzjBaseconfigService.selectWhzjBaseconfigList(whzjBaseconfig);
        ExcelUtil<WhzjBaseconfig> util = new ExcelUtil<WhzjBaseconfig>(WhzjBaseconfig.class);
        return util.exportExcel(list, "baseconfig");
    }

    /**
     * 新增基本设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存基本设置
     */
    @RequiresPermissions("whzj:baseconfig:add")
    @Log(title = "基本设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WhzjBaseconfig whzjBaseconfig)
    {
        return toAjax(whzjBaseconfigService.insertWhzjBaseconfig(whzjBaseconfig));
    }

    /**
     * 修改基本设置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WhzjBaseconfig whzjBaseconfig = whzjBaseconfigService.selectWhzjBaseconfigById(id);
        mmap.put("whzjBaseconfig", whzjBaseconfig);
        return prefix + "/edit";
    }

    /**
     * 修改基本设置
     */
    @GetMapping("/editProfile/{id}")
    public String editProfile(@PathVariable("id") String id, ModelMap mmap)
    {
        WhzjBaseconfig whzjBaseconfig = whzjBaseconfigService.selectWhzjBaseconfigById(id);
        mmap.put("whzjBaseconfig", whzjBaseconfig);
        return prefix + "/editProfile";
    }

    /**
     * 修改保存基本设置
     */
    @RequiresPermissions("whzj:baseconfig:edit")
    @Log(title = "基本设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WhzjBaseconfig whzjBaseconfig)
    {
        return toAjax(whzjBaseconfigService.updateWhzjBaseconfig(whzjBaseconfig));
    }

    /**
     * 删除基本设置
     */
    @RequiresPermissions("whzj:baseconfig:remove")
    @Log(title = "基本设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(whzjBaseconfigService.deleteWhzjBaseconfigByIds(ids));
    }
}
